package Twice.day11;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/8/6
 * @Version: 1.0
 */
public class HashSetDemo {
    public static void main(String[] args) {
        Set<User> users = new HashSet<>();

        User u1 = new User(1,"tom");
        User u2 = new User(2,"jack");
        User u3 = new User(1,"james");//拒绝添加的
        User u4 = new User(3,"jamess");
        User u5 = new User(4,"jamessss");

        users.add(u1);
        users.add(u2);
        users.add(u3);
        users.add(u4);
        users.add(u5);

        //遍历
        Iterator<User> iterator = users.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }

    }
}
